﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NNFramework.NeuroLibrary.WPFUserControls
{
    /// <summary>
    /// Interaction logic for NeuronViewer.xaml
    /// </summary>
    public partial class NeuronViewer : UserControl
    {
        private clsNeuron<int, int> mclnNeuron;
        public clsNeuron<int, int> Neuron
        {
            get
            {
                return mclnNeuron;
            }
            set
            {
                if (value != mclnNeuron && value != null)
                {
                    mclnNeuron = value;
                    DrawNeuron();
                }
            }
        }
        public NeuronViewer()
        {
            InitializeComponent();
        }

        public void DrawNeuron()
        {
            lblFunctionName.Content = mclnNeuron.ActivationFunction;
            lblAxonValue.Content = mclnNeuron.Axon;
            lblNeuronType.Content =
                mclnNeuron.GetType().FullName.Replace("`2", "").Replace((typeof (int)).AssemblyQualifiedName, "int").
                    Replace("[i", "i").Replace("t]", "t").Replace("[", "<").Replace("]", ">");
            lblWarning.Visibility = mclnNeuron.DendritesCount > 5 ? Visibility.Visible : Visibility.Hidden;
            var Dendrites = mclnNeuron.GetDendrites();
            //This part should be reviewed, not good code at all, shame on me...
            if (Dendrites.Count >= 1)
            {
                rtgD1.Visibility = Visibility.Visible;
                rtgD1C.Visibility = Visibility.Visible;
                lblD1.Visibility = Visibility.Visible;
                lblD1.Content = Dendrites[0].DendriteValue;
                lblW1.Visibility = Visibility.Visible;
                lblW1.Content = Dendrites[0].DendriteWeight;
                linConnection1.Visibility = Visibility.Visible;
            }
            if (Dendrites.Count >= 2)
            {
                rtgD2.Visibility = Visibility.Visible;
                rtgD2C.Visibility = Visibility.Visible;
                lblD2.Visibility = Visibility.Visible;
                lblD2.Content = Dendrites[1].DendriteValue;
                lblW2.Visibility = Visibility.Visible;
                lblW2.Content = Dendrites[1].DendriteWeight;
                linConnection2.Visibility = Visibility.Visible;
            }
            if (Dendrites.Count >= 3)
            {
                rtgD3.Visibility = Visibility.Visible;
                rtgD3C.Visibility = Visibility.Visible;
                lblD3.Visibility = Visibility.Visible;
                lblD3.Content = Dendrites[2].DendriteValue;
                lblW3.Visibility = Visibility.Visible;
                lblW3.Content = Dendrites[2].DendriteWeight;
                linConnection3.Visibility = Visibility.Visible;
            }
            if (Dendrites.Count >= 4)
            {
                rtgD4.Visibility = Visibility.Visible;
                rtgD4C.Visibility = Visibility.Visible;
                lblD4.Visibility = Visibility.Visible;
                lblD4.Content = Dendrites[3].DendriteValue;
                lblW4.Visibility = Visibility.Visible;
                lblW4.Content = Dendrites[3].DendriteWeight;
                linConnection4.Visibility = Visibility.Visible;
            }

            if (Dendrites.Count >= 5)
            {
                rtgD5.Visibility = Visibility.Visible;
                rtgD5C.Visibility = Visibility.Visible;
                lblD5.Visibility = Visibility.Visible;
                lblD5.Content = Dendrites[4].DendriteValue;
                lblW5.Visibility = Visibility.Visible;
                lblW5.Content = Dendrites[4].DendriteWeight;
                linConnection5.Visibility = Visibility.Visible;
            }
        }
    }
}
